<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            background-color: #000;
        }

        #canvas,#canvas1 {
            background: #fff;
        }
    </style>
</head>

<body>
    <canvas id="canvas" width="1000" height="300"></canvas>
    <canvas id="canvas1" width="1000" height="300"></canvas>
    <script>
        // 绘制矩形
        let canvas = document.getElementById('canvas');
        let canvas1 = document.getElementById('canvas1');
        let ctx = canvas.getContext('2d');
        let ctx1 = canvas1.getContext('2d');

        function d2a(n) {
            return n * Math.PI / 180;
        }

        ctx.__proto__.fnMove = function(arr, fn){
            canvas.onmousemove = (ev)=>{
                let x = ev.offsetX, y = ev.offsetY;
                let dis = Math.sqrt(Math.pow(x - arr[0], 2) + Math.pow(y - arr[1], 2));
                if (dis <= arr[2]) {
                    fn();
                }
            }
        }

        ctx.strokeStyle = 'red';
        ctx.arc(150, 200, 100, d2a(0), d2a(360), false);
        ctx.stroke();

        ctx.fnMove([150, 200, 100], function(_this) {
            let r = Math.floor((Math.random() * 999)) + ''
            let c = r.length < 3 ? '#0' + r : '#' + r;
            _this.fillStyle = c;
            _this.fillRect(60, 60, 180, 180);
        });

    </script>
</body>

</html>